package com.stedu.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.stedu.bean.Student;
import com.stedu.exception.SteduException;
import com.stedu.mapper.AdminStudentMapper;
import com.stedu.service.AdminStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminStudentServiceImpl implements AdminStudentService {
    @Autowired
    private AdminStudentMapper adminStudentMapper;
    @Override
    public Student loginStudent(String sno, String spassword) throws SteduException {
        Student student = adminStudentMapper.selectBySno(sno);
        if (student == null){
            throw new SteduException("用户名错误，请重新登录");
        }
        //对用户输入的密码进行加密，两次MD5加密
        String s = SecureUtil.md5(SecureUtil.md5(spassword));
        if (!s.equals(student.getSpassword())){
            throw new SteduException("密码错误，请重新登录");
        }
        return student;
    }
}
